#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   BOOT_ControlDTCSetting_0x85_test.py
@Time    :   2025/04/03 13:31:28
@Author  :   YangLiang 
@Version :   1.0
@Contact :   yangl@genvict.com
@License :   (C)Copyright 2022-2025
@Desc    :   UDS 0x85 DTC控制服务测试
'''

from pytest_assume.plugin import assume
import pytest
import logging
import time
from commDriver.TS_CAN import *
import allure
import sys
sys.dont_write_bytecode = True

# region 测试数据定义
ControlDTCSetting_NRC7F = [
    ("85 01", "7F 85 7F"),          # 
    ("85 02", "7F 85 7F"),          #
    ("85 81", "7F 85 7F"),          #
    ("85 82", "7F 85 7F"),          #
    ("85 03", "7F 85 7F"),          # 子功能03 7F>12
    ("85 84", "7F 85 7F"),          # 子功能04 7F>12
    ("85 01 00", "7F 85 7F"),       # 子功能04 7F>13
    ("85 81 00", "7F 85 7F"),       # 子功能04 7F>13
]
# endregion

# region 物理寻址测试
class Test_BOOT_ControlDTCSetting_Phy:
    """物理寻址模式测试（仅支持扩展会话）"""
    @allure.severity('normal')
    @allure.title('物理寻址-编程会话-NRC7F测试')
    @allure.description('物理寻址编程会话下NRC7F')
    @pytest.mark.parametrize('req,resp', ControlDTCSetting_NRC7F,
                           ids=[f"Req:{req}" for req, _ in ControlDTCSetting_NRC7F])
    def test_ControlDTCSetting_NRC7F_Programming_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    @allure.severity('critical')
    @allure.title('物理寻址-编程会话-NRC7F/NRC22优先级验证')
    @allure.description('验证物理寻址编程会话下NRC响应顺序：7F > 22')
    def test_ControlDTCSetting_NRC7F_NRC22_Priority_Programming_Phy(self, action, Driver):
        iStep = 1
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '10 03', '50 03', 0, iStep, False)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '10 02', '50 02', 0, iStep, False)
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 5)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '85 01', '7F 85 7F', 0, iStep, False)
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '85 01', '7F 85 7F', 0, iStep, False)
# endregion

# region 功能寻址测试
class Test_APP_ControlDTCSetting_Func:
    """功能寻址模式测试（仅支持扩展会话）"""
    
    @allure.severity('normal')
    @allure.title('功能寻址-编程会话-NRC7F测试')
    @allure.description('功能寻址编程会话下NRC7F')
    @pytest.mark.parametrize('req,resp', ControlDTCSetting_NRC7F,
                           ids=[f"Req:{req}" for req, _ in ControlDTCSetting_NRC7F])
    def test_ControlDTCSetting_NRC7F_Programming_Func(self, action, Driver, req, resp):
        iStep = 1
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun')

    @allure.severity('critical')
    @allure.title('功能寻址-编程会话-NRC7F/NRC22优先级验证')
    @allure.description('验证功能寻址编程会话下NRC响应顺序：7F > 22')
    def test_ControlDTCSetting_NRC7F_NRC22_Priority_Programming_Func(self, action, Driver):
        iStep = 1
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '10 03', '50 03', 0, iStep, False)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '10 02', '50 02', 0, iStep, False)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '3E 00', '7E 00', 0, iStep, False)
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 5)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '85 01', '', 0, iStep, False, 'UDSFun')
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '3E 00', '7E 00', 0, iStep, False)
        iStep = Driver['CAN'].SetVehicleSpeed(Driver, iStep, 0)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '3E 00', '7E 00', 0, iStep, False)
        iStep, _, _ = Driver['CAN'].checkReqResp(Driver, '85 01', '', 0, iStep, False, 'UDSFun')
# endregion